const processInitial = require('./01initial');
const processEmit = require('./02emit');
class TestCompilerPlugin {
  /**
   *
   * @param {import('webpack').Compiler} compiler
   */
  apply(compiler) {
    const name = '个人测试 TestCompilerPlugin';

    processInitial(compiler);
    // ---------------------------------------------------------------------------------------

    compiler.hooks.normalModuleFactory.tap(name, (normalModuleFactory) => {
      console.log('========= normalModuleFactory');
    });
    compiler.hooks.contextModuleFactory.tap(name, (contextModuleFactory) => {
      console.log('========= contextModuleFactory');
    });
    compiler.hooks.beforeCompile.tapAsync(name, (compilationParams, callback) => {
      console.log('========= beforeCompile');
      callback();
    });
    compiler.hooks.compile.tap(name, (compilationParams) => {
      console.log('========= compile');
    });
    compiler.hooks.thisCompilation.tap(name, (compilation, compilationParams) => {
      console.log('========= thisCompilation');
    });
    compiler.hooks.compilation.tap(name, (compilation, compilationParams) => {
      console.log('========= compilation');
    });

    compiler.hooks.make.tapAsync(name, (compilation, callback) => {
      console.log('========= make');
      callback();
    });
    compiler.hooks.finishMake.tapAsync(name, (compilation, callback) => {
      console.log('========== finishMake');
      callback();
    });
    compiler.hooks.afterCompile.tapAsync(name, (compilation, callback) => {
      console.log('========= afterCompile');
      callback();
    });

    // -----------------------------------------------------------------------------------------

    processEmit(compiler);

    /** ******************************************************************************** */
    compiler.hooks.beforeRun.tapAsync(name, (compiler, callback) => {
      console.log('========= beforeRun');
      callback();
    });
    compiler.hooks.run.tapAsync(name, (compiler, callback) => {
      console.log('========= run');
      callback();
    });

    compiler.hooks.watchRun.tapAsync(name, (compiler, callback) => {
      console.log('========= watchRun');
      callback();
    });

    compiler.hooks.invalid.tap(name, (fileName, changeTime) => {
      console.log('========= invalid');
    });

    compiler.hooks.watchClose.tap(name, () => {
      console.log('========= watchClose');
    });

    // ------------------------------------------------------------------------------
    compiler.hooks.additionalPass.tapAsync(name, (callback) => {
      console.log('========= additionalPass');
      callback();
    });
    compiler.hooks.failed.tap(name, (error) => {
      console.log('========= failed');
    });

    // compiler.hooks.infrastructureLog.tap(name, (name, type, args) => {
    //   console.log("========= infrastructureLog", name, type, args);
    // });
    // compiler.hooks.log.tap(name, (origin, logEntry) => {
    //   console.log("========= log");
    // });
  }
}

exports.TestCompilerPlugin = TestCompilerPlugin;
exports.FactoryParserHook = require('./factory-hook-plugin');
